// 引入 request 方法，假设 request 方法已经定义在某个工具文件中
import request from '/@/utils/request';
import { DbColumnInput,DbTableInput,CreateEntityInput,CreateSeedDataInput,DeleteDbColumnInput,DeleteDbTableInput,UpdateDbColumnInput,UpdateDbTableInput } from '../models';
// 定义 API 路径枚举
enum Api {
    SysDatabaseAddColumn = '/sysDatabase/addColumn',
    SysDatabaseAddTable = '/sysDatabase/addTable',
    SysDatabaseBackupDatabase = '/sysDatabase/backupDatabase',
    SysDatabaseColumnList = '/sysDatabase/columnList/{tableName}/{configId}',
    SysDatabaseCreateEntity = '/sysDatabase/createEntity',
    SysDatabaseCreateSeedData = '/sysDatabase/createSeedData',
    SysDatabaseDbTypeList = '/sysDatabase/dbTypeList/{configId}',
    SysDatabaseDeleteColumn = '/sysDatabase/deleteColumn',
    SysDatabaseDeleteTable = '/sysDatabase/deleteTable',
    SysDatabaseList = '/sysDatabase/list',
    SysDatabaseTableList = '/sysDatabase/tableList/{configId}',
    SysDatabaseUpdateColumn = '/sysDatabase/updateColumn',
    SysDatabaseUpdateTable = '/sysDatabase/updateTable',
    SysDatabaseVisualDbTable = '/sysDatabase/visualDbTable',
}

// 定义 API 方法
/**
 * 增加列 🔖
 * @param body 请求体
 */
export const apiSysDatabaseAddColumnPost = (body?: DbColumnInput) =>
    request({
        url: Api.SysDatabaseAddColumn,
        method: 'post',
        data: body,
    });

/**
 * 增加表 🔖
 * @param body 请求体
 */
export const apiSysDatabaseAddTablePost = (body?: DbTableInput) =>
    request({
        url: Api.SysDatabaseAddTable,
        method: 'post',
        data: body,
    });

/**
 * 备份数据库（PostgreSQL）🔖
 */
export const apiSysDatabaseBackupDatabasePost = () =>
    request({
        url: Api.SysDatabaseBackupDatabase,
        method: 'post',
    });

/**
 * 获取字段列表 🔖
 * @param tableName 表名
 * @param configId 配置ID
 */
export const apiSysDatabaseColumnListTableNameConfigIdGet = (tableName: string, configId: string) =>
    request({
        url: Api.SysDatabaseColumnList.replace('{tableName}', encodeURIComponent(tableName)).replace('{configId}', encodeURIComponent(configId)),
        method: 'get',
    });

/**
 * 创建实体 🔖
 * @param body 请求体
 */
export const apiSysDatabaseCreateEntityPost = (body?: CreateEntityInput) =>
    request({
        url: Api.SysDatabaseCreateEntity,
        method: 'post',
        data: body,
    });

/**
 * 创建种子数据 🔖
 * @param body 请求体
 */
export const apiSysDatabaseCreateSeedDataPost = (body?: CreateSeedDataInput) =>
    request({
        url: Api.SysDatabaseCreateSeedData,
        method: 'post',
        data: body,
    });

/**
 * 获取数据库数据类型列表 🔖
 * @param configId 配置ID
 */
export const apiSysDatabaseDbTypeListConfigIdGet = (configId: string) =>
    request({
        url: Api.SysDatabaseDbTypeList.replace('{configId}', encodeURIComponent(configId)),
        method: 'get',
    });

/**
 * 删除列 🔖
 * @param body 请求体
 */
export const apiSysDatabaseDeleteColumnPost = (body?: DeleteDbColumnInput) =>
    request({
        url: Api.SysDatabaseDeleteColumn,
        method: 'post',
        data: body,
    });

/**
 * 删除表 🔖
 * @param body 请求体
 */
export const apiSysDatabaseDeleteTablePost = (body?: DeleteDbTableInput) =>
    request({
        url: Api.SysDatabaseDeleteTable,
        method: 'post',
        data: body,
    });

/**
 * 获取库列表 🔖
 */
export const apiSysDatabaseListGet = () =>
    request({
        url: Api.SysDatabaseList,
        method: 'get',
    });

/**
 * 获取表列表 🔖
 * @param configId 配置ID
 */
export const apiSysDatabaseTableListConfigIdGet = (configId: string) =>
    request({
        url: Api.SysDatabaseTableList.replace('{configId}', encodeURIComponent(configId)),
        method: 'get',
    });

/**
 * 编辑列 🔖
 * @param body 请求体
 */
export const apiSysDatabaseUpdateColumnPost = (body?: UpdateDbColumnInput) =>
    request({
        url: Api.SysDatabaseUpdateColumn,
        method: 'post',
        data: body,
    });

/**
 * 编辑表 🔖
 * @param body 请求体
 */
export const apiSysDatabaseUpdateTablePost = (body?: UpdateDbTableInput) =>
    request({
        url: Api.SysDatabaseUpdateTable,
        method: 'post',
        data: body,
    });

/**
 * 获取可视化库表结构 🔖
 */
export const apiSysDatabaseVisualDbTableGet = () =>
    request({
        url: Api.SysDatabaseVisualDbTable,
        method: 'get',
    });